﻿// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    var nav = WinJS.Navigation;

    WinJS.UI.Pages.define("/pages/listingPage/index.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        itemInvoked: function (args) {
            var item = args.detail;
            nav.navigate("/pages/itemdetail/itemdetail.html", { itemID: item.itemPromise._value.data.Id });
        },
        ready: function (element, options) {
            // TODO: Initialize the page here.
            element.querySelector('.listingH2').innerText = options.title;
            var listView = element.querySelector('#imageTextList').winControl;

            if (options.title == 'JOGOS')
                listView.itemDataSource = JogosListing.dataSource;
            else if (options.title == 'NOVIDADES')
                listView.itemDataSource = NovidadesListing.dataSource;
            else if(options.title == 'DESTAQUES')
                listView.itemDataSource = DestaquesListing.dataSource;
            else
                listView.itemDataSource = TopListing.dataSource;

            listView.oniteminvoked = this.itemInvoked.bind(this);
        },

        unload: function () {
            // TODO: Respond to navigations away from this page.
        },

        updateLayout: function (element, viewState, lastViewState) {
            /// <param name="element" domElement="true" />
            
        }
    });
})();
